package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.JobGovernmentBill;
import com.ruoyi.system.mapper.JobGovernmentBillMapper;
import com.ruoyi.system.service.JobGovernmentBillService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 作业票政府上传(JobGovernmentBill)表服务实现类
 *
 * @author makejava
 * @since 2022-11-23 09:20:08
 */
@Service("jobGovernmentBillService")
public class JobGovernmentBillServiceImpl implements JobGovernmentBillService {
    @Resource
    private JobGovernmentBillMapper jobGovernmentBillDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public JobGovernmentBill queryById(Integer id) {
        return this.jobGovernmentBillDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param jobGovernmentBill 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<JobGovernmentBill> queryByPage(JobGovernmentBill jobGovernmentBill, PageRequest pageRequest) {
        long total = this.jobGovernmentBillDao.count(jobGovernmentBill);
        return new PageImpl<>(this.jobGovernmentBillDao.queryAllByLimit(jobGovernmentBill, pageRequest), pageRequest, total);
    }

    @Override
    public List<JobGovernmentBill> queryAll(JobGovernmentBill jobGovernmentBill) {
        return jobGovernmentBillDao.queryAll(jobGovernmentBill);
    }

    /**
     * 新增数据
     *
     * @param jobGovernmentBill 实例对象
     * @return 实例对象
     */
    @Override
    public JobGovernmentBill insert(JobGovernmentBill jobGovernmentBill) {
        this.jobGovernmentBillDao.insert(jobGovernmentBill);
        return jobGovernmentBill;
    }

    /**
     * 修改数据
     *
     * @param jobGovernmentBill 实例对象
     * @return 实例对象
     */
    @Override
    public JobGovernmentBill update(JobGovernmentBill jobGovernmentBill) {
        this.jobGovernmentBillDao.update(jobGovernmentBill);
        return this.queryById(jobGovernmentBill.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.jobGovernmentBillDao.deleteById(id) > 0;
    }
}
